package com.xszx.controller;

import com.xszx.beans.User;
import com.xszx.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Author 信思智学
 * @Date 2024/5/30 10:59
 * @Description
 */
@Controller
public class MyController {

    @Autowired
    private UserDao userDao;

    @RequestMapping("/toLogin")
    public String toLogin(){
        return "login";
    }

    @RequestMapping("/login")
    public void login(User user){

        User user1 = userDao.findByUsernameAndPassword(user.getUsername(), user.getPassword());

        System.out.println("登录成功："+user1);
    }

    @RequestMapping("/add")
    public String add(User user){

        userDao.save(user);
        return "redirect:list";

    }

    @RequestMapping("/list")
    public String list(Model model){

        List<User> users = userDao.findAll();

        model.addAttribute("users",users);

        return "list";

    }

}
